package cn.llk.mall.entity.vo;

import cn.llk.mall.entity.GoodsOrderEntity;
import cn.llk.mall.entity.GoodsOrderItemEntity;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

/**
 * Created by like oN  2021-04-23 14:49
 */
@Data
public class GoodsOrderVO {

    private GoodsOrderEntity order;
    private List<GoodsOrderItemEntity> orderItems;

    public BigDecimal getOrderTotalMoney() {
        AtomicReference<BigDecimal> totalMoney = new AtomicReference<>(BigDecimal.ZERO);
        orderItems.forEach(items -> {
            BigDecimal totalPrice = items.getTotalPrice();
            totalMoney.set(totalMoney.get().add(totalPrice));
        });
        return totalMoney.get();
    }
}
